// author by welong
// zuowl@qq.com
// 2014-09-04  10:37
// PAT basic 1004

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct Stu
{
	char name[11];
	char id[11];
	int grade;
}stu, *pstu;

int main(int argc, char **argv)
{
	int  i, count;
	pstu head, max, min;

	scanf("%d", &count);

	head = (pstu)malloc(sizeof(stu) * count);
	for(i = 0; i < count; i++)
		scanf("%s %s %d", (head+i)->name, (head+i)->id, &(head+i)->grade);

	max = min = head;
	for(i = 0; i < count; i++)
	{
		if((head+i)->grade > max->grade)
			max = head + i;
		else if((head+i)->grade < min->grade)
			min = head + i;
	}

	printf("%s %s\n", max->name, max->id);
	printf("%s %s\n", min->name, min->id);
	return 0;
}